const BrowserWindow = require('electron').remote.BrowserWindow
const fs = require('fs')
const path = require('path')
const { remote } = require('electron')



window.onload = function () {
this.document.querySelector('#btn2').onclick = () => {
    newWin = new BrowserWindow({
      width: 500,
      height: 500,
    })
  newWin.loadFile(path.join(__dirname,'../static/yellow.html'))
  newWin.on('close', () => { newWin = null })
  }

  var mybaby = this.document.querySelector('#mybaby')
  var btn1 = this.document.querySelector('#btn1')
  btn1.onclick = function () {
    fs.readFile('xiaojiejie.txt', (err, data) => {
      mybaby.innerHTML = data
    })
  }
  
  this.document.querySelector('#mybtn3').onclick = () => {
    newWin = new BrowserWindow({
      width: 800,
      height: 800,
    })
    newWin.loadFile(newWin.loadFile(path.join(__dirname, '../static/openFile.html')))
    newWin.on('close', () => { win = null })
  }

}


var rigthTemplate = [
  { label: '粘贴' },
  { label: '复制' }
]
var m = remote.Menu.buildFromTemplate(rigthTemplate)

window.addEventListener('contextmenu', function (e) {
  //阻止当前窗口默认事件
  e.preventDefault();
  //把菜单模板添加到右键菜单
  m.popup({ window: remote.getCurrentWindow() })

})